package com.fumin.common;

import com.fumin.pojo.CoinCount;
import com.fumin.pojo.InvestmentRecord;
import com.fumin.pojo.Projects;

import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;

/**
 * Created by Lingo on 2018/4/21.
 */
public class CountCointFactory {

    private static String ETH_BASE= "1000000000000000000";
    private static String PROJECT_BASE= "1000";


    public static CoinCount getCountCoin(Integer level, String fatherPk, Projects projects, InvestmentRecord investmentRecord){
        BigDecimal txBigValue = new BigDecimal(investmentRecord.getAmount());
        String rewardCount=null;
        if (level==2){
            rewardCount = txBigValue.divide(new BigDecimal(ETH_BASE))
                    .multiply(new BigDecimal(projects.getLevel2()))
                    .divide(new BigDecimal(PROJECT_BASE))
                    .toPlainString();
        }else {
            rewardCount = txBigValue.divide(new BigDecimal(ETH_BASE))
                    .multiply(new BigDecimal(projects.getLevel3()))
                    .divide(new BigDecimal(PROJECT_BASE))
                    .toPlainString();
        }
        CoinCount coinCount = new CoinCount();
        coinCount.setPk(UUID.randomUUID().toString());
        coinCount.setUser_pk(Long.valueOf(fatherPk));
        coinCount.setCount(rewardCount);
        coinCount.setFactor(investmentRecord.getUser_id());
        coinCount.setLevel(level);
        return coinCount;

    }

}
